﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="update.aspx.cs" Inherits="HungryCrowd.location.update" MasterPageFile="~/master/Main.Master" %>
<asp:Content ContentPlaceHolderID="ContentPlaceHolder1" runat="server">

    <div class="formLayout">
        <asp:Label ID="lblHeader" runat="server" ClientIDMode="Static" Text="Create a Location"></asp:Label>
        <div class="col1" style="">
            <div style="float:left;">Name: </div>
            <div class="elementAlign">
                <asp:TextBox ID="txtName" runat="server" ClientIDMode="Static"></asp:TextBox></div>
        </div>
        <div style="width: 100%; float: left; margin-left: auto; margin-right: auto;">
            <asp:Button ID="btnSubmit" Text="Create" runat="server" Width="80px" ClientIDMode="Static" OnClick="btnSubmit_Click" />
            <input type="button" id="save" onclick="saveLocation();" value="Save" />
            <asp:HiddenField ID="hdLocation" runat="server" ClientIDMode="Static" />
        </div> 
    </div>
    <script type="text/javascript">
        $('#save').click(function () {            
            var obj = $('#hdLocation').val();
            var jsonObj = JSON.parse(obj);
            var dataToSend = { Location: JSON.stringify(jsonObj), MethodName: 'SaveLocation' };

            var options = {
                data: dataToSend,
                dataType: 'JSON',
                type: 'POST',
                url: '/server/ajax.aspx',
                success: function (response, status, XHR) {
                    if (status != 'success') {
                        debugger;
                        alert('Error occurred.' + XHR);
                    }
                    else {
                        debugger;

                        if (response.toLowerCase() == "true") {
                            $('.client').find("input[type=text], textarea").val("");
                            alert('success');

                        }
                    }
                }
            };
            $.ajax(options);
        });
    </script>
</asp:Content>
